package com.gbas.dblink;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Date;

public class JDBCParamsDefault implements JDBCParams {
    public void setParam(PreparedStatement ps, Object param, int position) throws SQLException {
        if (param instanceof Integer) {
            ps.setInt(position, (Integer) param);
        } else if (param instanceof String) {
            ps.setString(position, (String) param);
        } else if (param instanceof Long) {
            ps.setLong(position, (Long) param);
        } else if (param instanceof Timestamp) {
            ps.setTimestamp(position, (Timestamp) param);
        } else if (param instanceof Date) {
            ps.setDate(position, (Date) param);
        } else if (param instanceof java.util.Date) {
            ps.setDate(position, new Date(((java.util.Date)param).getTime()));
        } else if (param instanceof Boolean) {
            ps.setBoolean(position, (Boolean)param);
        } else if (param == null) {
            ps.setString(position, null);
        } else {
            throw new UnsupportedOperationException("Sin soporte para el la clase " + param.getClass().getName());
        }
    }
}
